

using System.Numerics;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_LengthSquared_RT : RT_Node
    {
        public RT_SingleValuePort InputVector_RT;

        public RT_SingleValuePort LengthSquared_RT;

        public Node_LengthSquared_RT(Node_LengthSquared sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            InputVector_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.InputVector, this);

            LengthSquared_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.LengthSquared, this);
            LengthSquared_RT.OnGetValue = GetLengthSquared;
        }

        public AValue GetLengthSquared(DAG_Executor executor)
        {
            var inVec = InputVector_RT.GetValue(executor);
            var vecType = inVec.ValueType;
            if (vecType == AValue.EValueType.Vector2)
            {
                Vector2 inVec2 = inVec.ToVector2().Item2;
                float lenSq = inVec2.LengthSquared();
                LengthSquared_RT.SourceValue.SetScalar(lenSq);
            }
            else if (vecType == AValue.EValueType.Vector3)
            {
                Vector3 inVec3 = inVec.ToVector3().Item2;
                float lenSq = inVec3.LengthSquared();
                LengthSquared_RT.SourceValue.SetScalar(lenSq);
            }
            return LengthSquared_RT.SourceValue;
        }
    }
}